package net.adriana.esaytool;

import java.util.Date;

import net.adriana.ui.LastWindow;

public class Logger {
	public static final int DEBUG = 0;
	public static final int WARING = 1;
	public static final int ERROR = 2;
	public static final int CHECK = 3;
	
	private static int logTo;
	private static int logLevel;
	
	static{
		String str = PropertyReader.get("logTo");
		if(str!=null) logTo = Integer.parseInt(str);
		else logTo = 1;
		str = PropertyReader.get("logLevel");
		if(str!=null) logLevel = Integer.parseInt(str);
		else logLevel = 3;
	}
	
	public static void log(int level,Object msg){
		switch(logTo){
		case 0:
			//不输出
			break;
		case 1:
			if(logLevel>=level){
				System.out.print("###LOGTIME "+new Date()+" = ");
				System.out.println(msg);
			}
			break;
		case 2:
			//输出到文件
			break;
		case 3:
			if(logLevel>=level){
				try{
					LastWindow.log.append((String)msg + "\n");
				}catch(Exception e){
					System.out.print("###LOGTIME "+new Date()+" = ");
					System.out.println(msg);
				}
			}
			break;
		}
	}
}
